package com.ztgf.sys.api.client;


import com.ztgf.common.constant.Result;
import com.ztgf.common.enums.CodeEnum;
import com.ztgf.sys.models.dto.SysMenuDTO;
import com.ztgf.sys.models.service.ISysMenuService;
import com.ztgf.sys.models.service.ISysRoleMenuRelationService;
import com.ztgf.sys.models.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 菜单  前端控制器
 * </p>
 *
 * @author YUE123
 * @since 2020-05-26
 */
@RestController
@RequestMapping("/api/sysMenu")
@Slf4j
@Api(value = "SysMenuApiController",tags = "菜单表Api接口")
public class SysMenuApiController {

    @DubboReference
    private ISysMenuService iSysMenuService;

    @DubboReference
    private ISysUserService sysUserService;

    @DubboReference
    private ISysRoleMenuRelationService sysRoleMenuRelationService;

    @PostMapping("/getMenuListByRoleId")
    @ApiOperation(value = "根据角色Id获取属于自己的菜单",notes = "根据角色Id获取属于自己的菜单")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<List<SysMenuDTO>> getMenuListByRoleId(Long id){
        List<SysMenuDTO> sysMenuDTOList = iSysMenuService.selectListByRoleId(id);
        return new Result<>(sysMenuDTOList);
    }

    @PostMapping("/get")
    @ApiOperation(value = "根据id查找",notes = "根据id查找")
    @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "query", dataType = "Long")
    public Result<SysMenuDTO> get(@RequestParam("id") Long id){
        if(id == null){
            return new Result<>(CodeEnum.FAIL_100002 );
        }
        SysMenuDTO sysMenuDTO = iSysMenuService.selectById(id);
        return new Result<>(sysMenuDTO);
    }

}

